﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZuoAlgorithms.Class013;

public class QueueStackAndCircularQueue
{
    public class Queue2
    {
        public int[] queue;
        public int l;
        public int r;

        // 加入操作的总次数上限是多少，一定要明确
        public Queue2(int n)
        {
            queue = new int[n];
            l = 0;
            r = 0;
        }

        // 调用任何方法之前，先调用这个方法来判断队列内是否有东西
        public bool IsEmpty()
        {
            return l == r;
        }

        public void Offer(int num)
        {
            queue[r++] = num;
        }

        public int Poll()
        {
            return queue[l++];
        }

        public int Head()
        {
            return queue[l];
        }

        public int Tail()
        {
            return queue[r - 1];
        }

        public int Size()
        {
            return r - l;
        }

    }

    public class Stack2
    {
        public int[] stack;
        public int size;

        // 同时在栈里的元素个数不会超过n
        public Stack2(int n)
        {
            stack = new int[n];
            size = 0;
        }

        // 调用任何方法之前，先调用这个方法来判断栈内是否有东西
        public bool IsEmpty()
        {
            return size == 0;
        }

        public void Push(int num)
        {
            stack[size++] = num;
        }

        public int Pop()
        {
            return stack[--size];
        }

        public int Peek()
        {
            return stack[size - 1];
        }

        public int Size()
        {
            return size;
        }
    }



}
